package com.example.SMS;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;

//数据库连接

public class DBUtil {
    //private static final String URL = "jdbc:mysql://localhost:3306/appdata?useSSL=false&serverTimezone=UTC";
    private static final String URL = "jdbc:mysql://localhost:3306/appdata";
    private static final String USER = "SMSmanager";
    private static final String PASSWORD = "SMS20250528";

    static {
        try {
            Class.forName("com.mysql.cj.jdbc.Driver"); // 显式加载驱动
        } catch (ClassNotFoundException e) {
            e.printStackTrace();
            throw new RuntimeException("MySQL JDBC Driver not found!");
        }
    }

    public static Connection getConnection() throws SQLException {
        String url = URL + "?allowPublicKeyRetrieval=true&useSSL=false&serverTimezone=UTC";
        return DriverManager.getConnection(URL, USER, PASSWORD);
    }
}


